// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "IWebSocket.h"
#include "Subsystems/GameInstanceSubsystem.h"
#include "XG_GameInstanceSubsystem.generated.h"



/**
 * 
 */
UCLASS()
class LEARNPLUGIN_API UXG_GameInstanceSubsystem : public UGameInstanceSubsystem,public FTickableGameObject
{
	GENERATED_BODY()
public:
	virtual bool ShouldCreateSubsystem(UObject* Outer) const override;

	/** Implement this for initialization of instances of the system */
	virtual void Initialize(FSubsystemCollectionBase& Collection) override;

	/** Implement this for deinitialization of instances of the system */
	virtual void Deinitialize() override;

protected:
	virtual void Tick(float DeltaTime) override;
	virtual bool IsTickable() const override;
	virtual TStatId GetStatId() const override;

public:
	UFUNCTION(BlueprintCallable)
	void CreateSocket();
	
	UFUNCTION(BlueprintCallable)
	void CloseSocket();

protected:
	void OnConnected();
	void OnConnectionError(const FString& ErrorText);
	void OnClosed(int32 StatusCode,const FString& ReasonText,bool bwasClean);
	void OnMessage(const FString& Message);
	void OnMessageSent(const FString& Message);
protected:
	TSharedPtr<IWebSocket> webSocket = nullptr;
	
	FString ServerURL = TEXT("");
	FString ServerProtected = TEXT("");

	FString AppId = TEXT("8f1e4c58");
	FString APIKey = TEXT("1017852c1d6a6169656d0ad027a28b25");
};
